<?php
/**
 * Created By Project
 * Author: 陈东
 * Copyright：陈东
 * Source Code：陈东
 * Explain：I shall not authorize for any other commercial purposes, law breakers must be prosecuted.
 */
namespace Admin\Controller;
use Think\Controller;

class UploadController extends BaseController {
	static $dir = './Uploads/';
	/*
	 * 单图片上传
	 */
	public function index(){
		$bakcontrool = I('get.bakcontrool','');
		if(I('get.submit')=='true'){
			$upload = new \Think\Upload();// 实例化上传类
			$upload->maxSize   =     3145728 ;// 设置附件上传大小
			$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
			$upload->rootPath  =      self::$dir; // 设置附件上传根目录
			// 上传单个文件
			$info   =   $upload->uploadOne($_FILES['uploadimg']);
			if(!$info) {
				  // 上传错误提示错误信息
				  //$this->error($upload->getError());
				  echo "<script>alert('".$upload->getError()."');</script>";
			}else{
				  // 上传成功 获取上传文件信息
				  $imgpath = $rootPath.$info['savepath'].$info['savename'];
				  $imgresult = "<img src='".$imgpath."' />";
				  //echo $result;
				  $this->assign('img',$imgresult);
			}
		}
		$this->assign('bcV',$bakcontrool);
		$this->assign('showfooler',$this->loopFun(self::$dir));
		$this->display();
	}
	
	public function loopFun($dir){
		//取出文件或者文件夹
		$list = scandir($dir);
		krsort($list);
		$location_dir = array();
		foreach($list as $f){
			if($f!='.' && $f!='..'){
				$location_dir[] = $f;
			}
		}
		return $location_dir;
	}
	
	public function showfile(){
		echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"/Public/css/main.css\" /><script type=\"text/javascript\" src=\"/Public/js/jquery-1.9.1.min.js\"></script><script type=\"text/javascript\" src=\"/Public/js/main.js\"></script>
	";
	    foreach($this->loopFun(self::$dir.'/'.I('get.fooler')) as $v){
    		echo "<a><img src='".ltrim(self::$dir,'.').I('get.fooler')."/".$v."' /></a>";
    	}
	}

}